//
//  RegisterView.m
//  HappyBaby
//
//  Created by lanou on 15/11/30.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "RegisterView.h"
#import "Define.h"
@interface RegisterView () <UITextFieldDelegate>

@property (nonatomic, strong) NSMutableArray *array;

@end

@implementation RegisterView

- (NSMutableArray *)array
{
    if (_array ==  nil) {
        self.array = [NSMutableArray array];
    }
    return _array;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor whiteColor];
    if (self) {
        CGFloat width = 260 * kScaleX;
        CGFloat x = (kScreenWidth - width)/2;
        CGFloat height = 30 * kScaleY;
        CGFloat ySpace = height + 40*kScaleY;
        NSArray *titleArray = @[@"昵称",@"邮箱",@"密码",@"请再次输入密码"];
        // 循环创建textFiled
        for (int i = 0; i < 4; i++) {
            UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(x, 50*kScaleY + ySpace * i, width, height)];
            textFiled.borderStyle = UITextBorderStyleBezel;
            textFiled.backgroundColor = [UIColor colorWithRed:226/255.0 green:226/255.0 blue:226/255.0 alpha:1];
            textFiled.placeholder = titleArray[i];
            textFiled.delegate = self;
            if (i == 2||i == 3) {
                textFiled.secureTextEntry = YES;
            }
            UIView *smallView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10*kScaleX, height)];
            textFiled.leftView = smallView;
            textFiled.leftViewMode = UITextFieldViewModeAlways;
            [self.array addObject:textFiled];
            [self addSubview:textFiled];
        }
        self.nickName = self.array[0];
        self.email = self.array[1];
        self.password = self.array[2];
        self.passwordAgian = self.array[3];
        self.submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.submitBtn.frame = CGRectMake(x, self.passwordAgian.y + ySpace, width, height) ;
        [self.submitBtn setTitle:@"注册" forState:UIControlStateNormal];
        self.submitBtn.backgroundColor = [UIColor colorWithRed:88/255.0 green:137/255.0 blue:236/255.0 alpha:1];
        [self addSubview:_submitBtn];
        
        self.simpleRegister = [UIButton buttonWithType:UIButtonTypeCustom];
        self.simpleRegister.frame = CGRectMake(x, self.submitBtn.y + ySpace, width, height);
        [self.simpleRegister setTitle:@"快速注册" forState:UIControlStateNormal];
        self.simpleRegister.backgroundColor = [UIColor colorWithRed:88/255.0 green:137/255.0 blue:236/255.0 alpha:1];
        [self addSubview:_simpleRegister];
        
        
    }
    return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.nickName resignFirstResponder];
    [self.email resignFirstResponder];
    [self.password resignFirstResponder];
    [self.passwordAgian resignFirstResponder];
}

@end
